﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace libReadWrite
{
    public class BigEndianWriterForBluetooth: BigEndianWriter
    {
        private readonly BinaryWriter mBaseWriter;

        public BigEndianWriterForBluetooth(BinaryWriter baseWriter)
        {
            mBaseWriter = baseWriter;
        }

        public override void Write(byte v)
        {
            mBaseWriter.Write(v);
        }

        public override void Write(byte[] buffer)
        {
            mBaseWriter.Write(buffer);
        }

        public override void Write(int v)
        {
            mBaseWriter.Write(ConvertToBigEndianBytes(BitConverter.GetBytes(v)));
        }

        public override byte[] ConvertToBigEndianBytes(byte[] input)
        {
            byte[] bytes = new byte[input.Length];
            int j = 0;
            for (int i = input.Length - 1; i >= 0; i--, j++)
                bytes[i] = input[j];

            return bytes;
        }

        public override void Write(long v)
        {
            mBaseWriter.Write(ConvertToBigEndianBytes(BitConverter.GetBytes(v)));
        }
    }
}
